﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment_2.Entities.Components
{
    class ModelComponent : DrawComponent
    {
        public Model Model { get; set; }

        private readonly Game1 _game;

        public ModelComponent(Entity owner, GraphicsDevice device, Game1 game, Model model)
            : base(owner, device)
        {
            _game = game;
            Model = model;
        }

        public override void Draw(BasicEffect effect)
        {

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (BasicEffect basicEffect in mesh.Effects)
                {
                    basicEffect.EnableDefaultLighting();
                    basicEffect.World = ((Typhoon)Owner).BoneTransforms[mesh.ParentBone.Index];
                    basicEffect.View = _game.Camera.View;
                    basicEffect.Projection = _game.Camera.Projection;
                }
                mesh.Draw();
            }
        }
    }
}
